//PITCH PROGRAM
//CLASS: Card
//	- functions to make cards, set card images, return 
//	card card suit and card face, determine if card
//	is certain card
//BY: ALEX TRACY
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Card 
{
	//set suit names and faces
	private static final String suits[] = { "H", "D", "C", "S" };
	private static final String faces[] = {"2", "3", "4", "5" , "6", "7", "8", "9", "T", "J", "Q", "K", "A"};
	private static BufferedImage cardImgs[] = new BufferedImage[52];
	private static BufferedImage backOfCard;
	
	//getCard
	//return the suit and value of the card
	static public String getCard(int card)
	{
			return faces[getFace(card)] + suits[getSuit(card)];
	}//End getCard
	
	//getFace
	//return the face of a card
	static public int getFace(int card)
	{
		return card % 13; 
	}//End getFace
	
	//getSuit
	//return the suit of a card
	static public int getSuit(int card)
	{
		return card / 13;
	}//end getSuit
	
	//Return the suit letter of a card
	static public String getSuitLetter(int card)
	{
		return suits[card];
	}//End getSuitLetter
	
	//return true if card is jack
	static public boolean isJack(int card)
	{
		if ( getFace(card) == 9)
		{
			return true;
		}
		else
		{
			return false;
		}
	}//end isJack
	
	//return true if card is two
	static public boolean isDeuce(int card)
	{
		if ( getFace(card) == 0)
		{
			return true;
		}
		else 
		{
			return false;
		}
	}//end isDeuce
	
	//return true if card is ten
	static public boolean isTen(int card)
	{
		if ( getFace(card) == 8)
		{
			return true;
		}
		else 
		{
			return false;
		}
	}//end isTen
	
	//initialize images of card faces and the back
	//of the cards
	public static void initImgs()
	{
		for(int i = 0; i<cardImgs.length; i++)
		{	
			try
			{
				cardImgs[i] = ImageIO.read(new File ("cards/" + 
						Card.getCard(i) + ".gif") );
				backOfCard = ImageIO.read(new File ("cards/b.gif") );
			}
			catch (IOException e)
			{
				System.err.print("error finding card file");
			}
		}	
	}//End initImgs
	
	//return card image if card is not equal to -1
	public static BufferedImage getCardImg(int c)
	{
		
		if (c == -1)
			return null;
		else
			return cardImgs[c];
	}//end getCardImg
	
	//return back of card if card is not -1
	public static BufferedImage getCardBack(int c)
	{
		if (c == -1)
		{
			return null;
		}
		else
		{
			return backOfCard;
		}
	}//end getCardBack
	
}//end Card class
